//
//  MM_HomeManageHeaderView.m
//  MallManage_IOS
//
//  Created by 张浩 on 2023/9/20.
//

#import "MM_HomeManageHeaderView.h"
#import "MM_ImageButton.h"

@interface MM_HomeManageHeaderView ()

@property (nonatomic, strong) MM_ImageButton *userImageBtn;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UIButton *numberBtn;
@property (nonatomic, strong) UIButton *codeBtn;

@end

@implementation MM_HomeManageHeaderView

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = MM_ColorUtil(@"#E8F1FF");
        
        _userImageBtn = [MM_ImageButton buttonWithType:UIButtonTypeCustom withSpace:2];        
//        [_userImageBtn setTitle:[MM_Cache shareMM_Cache].userModel.user_name forState:UIControlStateNormal];
        _userImageBtn.titleLabel.font = FONT(12);
        _userImageBtn.buttonStyle = FPButtonImageLeft;
        [_userImageBtn setTitleColor:MM_ColorUtil(@"#000000") forState:UIControlStateNormal];
        [_userImageBtn setImage:[UIImage imageNamed:@"depart_defaultHeader"] forState:UIControlStateNormal];
//        _collectionBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        [_userImageBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        _userImageBtn.padding = 2;
        _userImageBtn.tag = 100;
        [self addSubview:_userImageBtn];
        
        _nameLabel = [Custom_ZHTool uiLabelCreate:@"" Font:FONT(14) TextColor:MM_ColorUtil(@"#000000")];
        _nameLabel.text = [MM_Cache shareMM_Cache].userModel.user_name;
        [self addSubview:_nameLabel];
        
        _codeBtn = [Custom_ZHTool uiButtonCreate:nil Text:nil TextColor:nil TextFont:nil Image:MM_Image(@"homeCodeImage")];
        [_codeBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        _codeBtn.tag = 101;
        [self addSubview:_codeBtn];
        
        _numberBtn = [Custom_ZHTool uiButtonCreate:nil Text:nil TextColor:nil TextFont:nil Image:MM_Image(@"numberImage")];
        [_numberBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        _numberBtn.tag = 102;
        _numberBtn.hidden = YES;
        [self addSubview:_numberBtn];
        
        [self setUpViews];
    }
    return self;
}

- (void)setUpViews {
    
    [self.userImageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(12);
        make.bottom.equalTo(self).offset(-6);
        make.width.height.equalTo(30);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.userImageBtn.mas_right).offset(5);
        make.centerY.equalTo(self.userImageBtn);
    }];
    
    [self.numberBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(self.codeBtn.mas_left).offset(-10);
        make.centerY.equalTo(self.userImageBtn);
        make.width.height.equalTo(26);
    }];
    
    [self.codeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.right.equalTo(-12);
        make.centerY.equalTo(self.userImageBtn);
        make.width.height.equalTo(26);
    }];
}

- (void)btnClick:(UIButton *)button {
    
    if (self.headerBlock) {
        self.headerBlock(button.tag - 100);
    }
}

@end
